<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('车辆使用记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
         <div class="modal fade" id="routeModal" tabindex="-1" role="dialog" aria-labelledby="routeModalLabel" aria-hidden="true">
             <div class="modal-dialog" role="document">
                 <div class="modal-content">
                     <div class="modal-header">
                         <h5 class="modal-title" id="routeModalLabel">路线图</h5>
                         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                             <span aria-hidden="true">&times;</span>
                         </button>
                     </div>
                     <div class="modal-body">
                         <img id="routeImage" src="" alt="路线图" style="width: 100%; height: auto;">
                     </div>
                     <div class="modal-footer">
                         <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                     </div>
                 </div>
             </div>
         </div>
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>车牌号：</label>
                                <input type="text" name="vehicleNumber"/>
                            </li>
                            <li>
                                <label>驾驶员编号：</label>
                                <input type="text" name="driverNumber"/>
                            </li>
<!--                            <li>-->
<!--                                <label>使用开始时间：</label>-->
<!--                                <input type="text" class="time-input" placeholder="请选择使用开始时间" name="startTime"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>使用结束时间：</label>-->
<!--                                <input type="text" class="time-input" placeholder="请选择使用结束时间" name="endTime"/>-->
<!--                            </li>-->
                            <li>
                                <label>使用状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="1">正在使用</option>
                                    <option value="2">已归还</option>
                                </select>
                            </li>
                            <li>
                                <label>行程信息：</label>
                                <input type="text" name="whereToWhere"/>
                            </li>
                            <li class="select-time">
                                <label>使用开始时间： </label>
                                <input type="text" class="time-input" name="startTimeOfUseBegin" placeholder="开始时间" />
                                <span>-</span>
                                <input type="text" class="time-input" name="endTimeOfUseBegin" placeholder="结束时间" />
                            </li>
                            <li class="select-time">
                                <label>使用结束时间： </label>
                                <input type="text" class="time-input" name="startTimeOfUseEnd" placeholder="开始时间" />
                                <span>-</span>
                                <input type="text" class="time-input" name="endTimeOfUseEnd" placeholder="结束时间"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:vehicleUsage:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:vehicleUsage:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:vehicleUsage:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:vehicleUsage:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:vehicleUsage:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:vehicleUsage:remove')}]];
        var retrunCarFlag = [[${@permission.hasPermi('system:vehicleUsage:retrunCar')}]];
        var prefix = ctx + "system/vehicleUsage";
        var returnCarUrl= prefix + "/returnCar";
        var routeImageUrl = prefix + "/getRouteImage"; // 这是获取图片的URL

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "车辆使用记录",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '使用记录ID',
                    visible: false
                },
                {
                    field: 'vehicleNumber',
                    title: '车牌号'
                },
                {
                    field: 'driverNumber',
                    title: '驾驶员编号'
                },
                {
                    field: 'startTime',
                    title: '使用开始时间'
                },
                {
                    field: 'endTime',
                    title: '使用结束时间'
                },
                {
                    field: 'statusName',
                    title: '使用状态'
                },
                {
                    field: 'whereToWhere',
                    title: '行程信息'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];


                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + '" href="javascript:void(0)" onclick="getRoute(\'' + row.whereToWhere + '\')"><i class="fa fa-edit"></i>获取路线</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + retrunCarFlag + '" href="javascript:void(0)" onclick="returnCar(\'' + row.id + '\')"><i class="fa fa-remove"></i>车辆归还</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function returnCar(id) {

            $.modal.confirm("确定归还该车辆吗？", function() {
                var url = returnCarUrl;
                var data = { "id":id};
                $.operate.submit(url, "post", "json", data);
            });
        }
        function getRoute(whereToWhere) {
            console.log("whereToWhere",whereToWhere)
            // 设置图片的URL
            var imageUrl ="";
            if(whereToWhere=="扬州市 到 仪征市")
            {
                imageUrl ="/route/1.jpg";
            }else if(whereToWhere=="扬州市 到 江都区")
            {
                imageUrl ="/route/2.jpg";
            }else if(whereToWhere=="扬州市 到 高邮市")
            {
                imageUrl ="/route/3.jpg";
            }
            // 将图片URL设置到模态框中的img标签
            $('#routeImage').attr('src', imageUrl);
            // 显示模态框
            $('#routeModal').modal('show');
        }
    </script>
</body>
</html>